﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Cstudy.DAL
{
    public class users
    {
        /// <summary>
        /// 创建新用户
        /// </summary>
        /// <param name="user">用户实体</param>
        /// <returns>返回成功与否</returns>
        public bool AddUser(MODEL.users user)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@username",user.UserName),
                new SqlParameter("@pwd",user.Pwd),
                new SqlParameter("@email",user.Email)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_AddUser", parms);
        }

        public bool ExistUserName(string userName)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@name",userName)
            };
            if ((int)COM.SQLHelper.ExecuteScalar("sp_ExitsUserName", parms) == 0)
                return false;
            else
                return true;
        }

        public bool UpdateUser(MODEL.users user)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@userid",user.UserID),
                new SqlParameter("@username",user.UserName),
                new SqlParameter("@pwd",user.Pwd),
                new SqlParameter("@email",user.Email),
                new SqlParameter("@userpower",user.UserPower),
                new SqlParameter("@sex",(int)user.Sex),
                new SqlParameter("@Email",user.Email),
                new SqlParameter("@nickname",user.NickName),
                new SqlParameter("@telephone",user.Telephone),
                new SqlParameter("@birth",user.Birth),
                new SqlParameter("@headimage",user.Headimage),
                new SqlParameter("@info",user.Info)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_UpdateUser", parms);
        }

    }
}
